using System.Drawing;
using System.Windows.Forms;
using Microsoft.WowAddonStudio.FrameXml.Components.Layout;
using Microsoft.WowAddonStudio.FrameXml.Components.Support;
using Microsoft.WowAddonStudio.FrameXml.Components.Tests.Mocks;
using Microsoft.WowAddonStudio.FrameXml.Serialization;
using Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames;
using Microsoft.WowAddonStudio.FrameXml.Services;
using Microsoft.WowAddonStudio.Tests.Common.Mocks;

using NUnit.Framework;
using Button=Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames.Button;
using Color=Microsoft.WowAddonStudio.FrameXml.Serialization.Color;
using Font=Microsoft.WowAddonStudio.FrameXml.Serialization.Font;
using StatusBar=Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames.StatusBar;

namespace Microsoft.WowAddonStudio.FrameXml.Components.Tests.Components
{
	[TestFixture]
	public class SimpleControlsTest
	{
		private FrameXmlGraphics graphics;
		private ResourceFileLoader resourceFileLoader;
		private Control control;

		#region SetUp

		[TestFixtureSetUp]
		public void TestFixtureSetUp()
		{
			resourceFileLoader = new MockResourceFileLoader();
			FrameXmlImageService imageService = new MockFrameXmlImageService(resourceFileLoader);
			FrameXmlFontService fontService = new MockFrameXmlFontService(resourceFileLoader);
			control = new Control();
			graphics = new MockFrameXmlGraphics(imageService, fontService, control.CreateGraphics());
			SimpleTestServiceLocator.Register<FrameXmlLayoutEngine>(new MockFrameXmlLayoutEngine());
		}

		[SetUp]
		public void SetUp()
		{

		}

		#endregion

		#region TearDown

		[TearDown]
		public void TearDown()
		{

		}

		#endregion

		#region Tests

		[Test(Description = "")]
		public void Test_ButtonControl()
		{
			var buttonControl = new ButtonControl();
			Assert.AreEqual(typeof(Button), buttonControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Button), buttonControl.Button);
			Assert.IsNotNull(buttonControl.Button);

			var serializationObject = new Button { Name = "button1" };
			buttonControl = new ButtonControl(serializationObject);
			Assert.AreEqual(typeof(Button), buttonControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Button), buttonControl.Button);
			Assert.IsNotNull(buttonControl.Button);
			Assert.AreSame(serializationObject, buttonControl.SerializationObject);

			buttonControl.Button.NormalTexture = new Texture();
			buttonControl.DrawControl(graphics, buttonControl.Bounds);
		}

		[Test(Description = "")]
		public void Test_CheckButtonControl()
		{
			var checkButtonControl = new CheckButtonControl();
			Assert.AreEqual(typeof(CheckButton), checkButtonControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(CheckButton), checkButtonControl.CheckButton);
			Assert.IsNotNull(checkButtonControl.CheckButton);

			var checkButton = new CheckButton { Name = "checkButton1" };
			checkButtonControl = new CheckButtonControl(checkButton);
			Assert.AreEqual(typeof(CheckButton), checkButtonControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(CheckButton), checkButtonControl.CheckButton);
			Assert.IsNotNull(checkButtonControl.CheckButton);
			Assert.AreSame(checkButton, checkButtonControl.SerializationObject);

			checkButtonControl.CheckButton.Checked = true;
			checkButtonControl.CheckButton.CheckedTexture = new Texture();
			checkButtonControl.DrawControl(graphics, checkButtonControl.Bounds);
		}

		[Test(Description = "")]
		public void Test_ColorSelectControl()
		{
			var frameXmlControl = new ColorSelectControl();
			Assert.AreEqual(typeof(ColorSelect), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(ColorSelect), frameXmlControl.ColorSelect);
			Assert.IsNotNull(frameXmlControl.ColorSelect);

			var serializationObject = new ColorSelect { Name = "frameXmlControl1" };
			frameXmlControl = new ColorSelectControl(serializationObject);
			Assert.AreEqual(typeof(ColorSelect), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(ColorSelect), frameXmlControl.ColorSelect);
			Assert.IsNotNull(frameXmlControl.ColorSelect);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_EditBoxControl()
		{
			var frameXmlControl = new EditBoxControl();
			Assert.AreEqual(typeof(EditBox), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(EditBox), frameXmlControl.EditBox);
			Assert.IsNotNull(frameXmlControl.EditBox);

			var serializationObject = new EditBox { Name = "frameXmlControl1" };
			frameXmlControl = new EditBoxControl(serializationObject);
			Assert.AreEqual(typeof(EditBox), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(EditBox), frameXmlControl.EditBox);
			Assert.IsNotNull(frameXmlControl.EditBox);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_FontComponent()
		{
			var frameXmlControl = new FontComponent();
			Assert.IsInstanceOfType(typeof(Font), frameXmlControl.Font);
			Assert.IsNotNull(frameXmlControl.Font);

			var serializationObject = new Font { Name = "frameXmlControl1" };
			frameXmlControl = new FontComponent(serializationObject);
			Assert.IsInstanceOfType(typeof(Font), frameXmlControl.Font);
			Assert.IsNotNull(frameXmlControl.Font);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_FontStringControl()
		{
			var frameXmlControl = new FontStringControl();
			Assert.AreEqual(typeof(FontString), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(FontString), frameXmlControl.FontString);
			Assert.IsNotNull(frameXmlControl.FontString);

			var serializationObject = new FontString { Name = "frameXmlControl1" };
			frameXmlControl = new FontStringControl(serializationObject);
			Assert.AreEqual(typeof(FontString), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(FontString), frameXmlControl.FontString);
			Assert.IsNotNull(frameXmlControl.FontString);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);

			frameXmlControl.FontString.Font = "TestFont";
			frameXmlControl.FontString.Text = "Test";
			frameXmlControl.FontString.FontHeight = new FontHeight {AbsValue = new AbsValue {Value = 10}};
			frameXmlControl.FontString.Color = new Color();
			frameXmlControl.DrawControl(graphics, frameXmlControl.Bounds);
		}


		[Test(Description = "")]
		public void Test_FrameControl()
		{
			var frameXmlControl = new FrameControl();
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Frame), frameXmlControl.Frame);
			Assert.IsNotNull(frameXmlControl.Frame);

			var serializationObject = new Frame { Name = "frameXmlControl1" };
			frameXmlControl = new FrameControl(serializationObject);
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Frame), frameXmlControl.Frame);
			Assert.IsNotNull(frameXmlControl.Frame);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);

			frameXmlControl.Frame.Backdrop = new Backdrop {EdgeFile = "TestEdgeFile"};
			frameXmlControl.DrawControl(graphics, frameXmlControl.Bounds);
		}

		[Test(Description = "")]
		public void Test_GameTooltipComponent()
		{
			var frameXmlControl = new GameTooltipComponent();
			Assert.IsInstanceOfType(typeof(GameTooltip), frameXmlControl.GameTooltip);
			Assert.IsNotNull(frameXmlControl.GameTooltip);

			var serializationObject = new GameTooltip { Name = "frameXmlControl1" };
			frameXmlControl = new GameTooltipComponent(serializationObject);
			Assert.IsInstanceOfType(typeof(GameTooltip), frameXmlControl.GameTooltip);
			Assert.IsNotNull(frameXmlControl.GameTooltip);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}


		[Test(Description = "")]
		public void Test_MessageFrameControl()
		{
			var frameXmlControl = new MessageFrameControl();
			Assert.AreEqual(typeof(MessageFrame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(MessageFrame), frameXmlControl.MessageFrame);
			Assert.IsNotNull(frameXmlControl.MessageFrame);

			var serializationObject = new MessageFrame { Name = "frameXmlControl1" };
			frameXmlControl = new MessageFrameControl(serializationObject);
			Assert.AreEqual(typeof(MessageFrame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(MessageFrame), frameXmlControl.MessageFrame);
			Assert.IsNotNull(frameXmlControl.MessageFrame);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_MinimapControl()
		{
			var frameXmlControl = new MinimapControl();
			Assert.AreEqual(typeof(Minimap), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Minimap), frameXmlControl.Minimap);
			Assert.IsNotNull(frameXmlControl.Minimap);
			var serializationObject = new Minimap { Name = "frameXmlControl1" };

			frameXmlControl = new MinimapControl(serializationObject);
			Assert.AreEqual(typeof(Minimap), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Minimap), frameXmlControl.Minimap);
			Assert.IsNotNull(frameXmlControl.Minimap);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_ModelControl()
		{
			var frameXmlControl = new ModelControl();
			Assert.AreEqual(typeof(Model), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Model), frameXmlControl.Model);
			Assert.IsNotNull(frameXmlControl.Model);
			var serializationObject = new Model { Name = "frameXmlControl1" };

			frameXmlControl = new ModelControl(serializationObject);
			Assert.AreEqual(typeof(Model), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Model), frameXmlControl.Model);
			Assert.IsNotNull(frameXmlControl.Model);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_MovieFrameControl()
		{
			var frameXmlControl = new MovieFrameControl();
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(MovieFrame), frameXmlControl.MovieFrame);
			//Assert.IsNotNull(frameXmlControl.MovieFrame);
			var serializationObject = new MovieFrame { Name = "frameXmlControl1" };

			frameXmlControl = new MovieFrameControl(serializationObject);
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(MovieFrame), frameXmlControl.MovieFrame);
			//Assert.IsNotNull(frameXmlControl.MovieFrame);
			//Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_PlayerModelControl()
		{
			var frameXmlControl = new PlayerModelControl();
			Assert.AreEqual(typeof(Model), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(PlayerModel), frameXmlControl.PlayerModel);
			//Assert.IsNotNull(frameXmlControl.PlayerModel);
			var serializationObject = new PlayerModel { Name = "frameXmlControl1" };

			frameXmlControl = new PlayerModelControl(serializationObject);
			Assert.AreEqual(typeof(Model), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(PlayerModel), frameXmlControl.PlayerModel);
			//Assert.IsNotNull(frameXmlControl.PlayerModel);
			//Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_ScrollFrameControl()
		{
			var frameXmlControl = new ScrollFrameControl();
			Assert.AreEqual(typeof(ScrollFrame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(ScrollFrame), frameXmlControl.ScrollFrame);
			Assert.IsNotNull(frameXmlControl.ScrollFrame);
			var serializationObject = new ScrollFrame { Name = "frameXmlControl1" };

			frameXmlControl = new ScrollFrameControl(serializationObject);
			Assert.AreEqual(typeof(ScrollFrame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(ScrollFrame), frameXmlControl.ScrollFrame);
			Assert.IsNotNull(frameXmlControl.ScrollFrame);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_ScrollingMessageFrame()
		{
			var frameXmlControl = new ScrollingMessageFrameControl();
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(ScrollingMessageFrame), frameXmlControl.ScrollingMessageFrame);
			//Assert.IsNotNull(frameXmlControl.ScrollingMessageFrame);
			var serializationObject = new ScrollingMessageFrame { Name = "frameXmlControl1" };

			frameXmlControl = new ScrollingMessageFrameControl(serializationObject);
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(ScrollingMessageFrame), frameXmlControl.ScrollingMessageFrame);
			//Assert.IsNotNull(frameXmlControl.ScrollingMessageFrame);
			//Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_SimpleHTMLControl()
		{
			var frameXmlControl = new SimpleHTMLControl();
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(ScrollingMessageFrame), frameXmlControl.ScrollingMessageFrame);
			//Assert.IsNotNull(frameXmlControl.ScrollingMessageFrame);
			var serializationObject = new SimpleHTML { Name = "frameXmlControl1" };

			frameXmlControl = new SimpleHTMLControl(serializationObject);
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(ScrollingMessageFrame), frameXmlControl.ScrollingMessageFrame);
			//Assert.IsNotNull(frameXmlControl.ScrollingMessageFrame);
			//Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_SliderControl()
		{
			var frameXmlControl = new SliderControl();
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(Slider), frameXmlControl.Slider);
			//Assert.IsNotNull(frameXmlControl.Slider);
			var serializationObject = new Slider { Name = "frameXmlControl1" };

			frameXmlControl = new SliderControl(serializationObject);
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(ScrollingMessageFrame), frameXmlControl.Slider);
			//Assert.IsNotNull(frameXmlControl.Slider);
			//Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_StatusBarControl()
		{
			var frameXmlControl = new StatusBarControl();
			Assert.AreEqual(typeof(StatusBar), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(StatusBar), frameXmlControl.StatusBar);
			Assert.IsNotNull(frameXmlControl.StatusBar);
			var serializationObject = new StatusBar { Name = "frameXmlControl1" };

			frameXmlControl = new StatusBarControl(serializationObject);
			Assert.AreEqual(typeof(StatusBar), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(StatusBar), frameXmlControl.StatusBar);
			Assert.IsNotNull(frameXmlControl.StatusBar);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_TabardModelControl()
		{
			var frameXmlControl = new TabardModelControl();
			Assert.AreEqual(typeof(TabardModel), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(TabardModel), frameXmlControl.TabardModel);
			Assert.IsNotNull(frameXmlControl.TabardModel);
			var serializationObject = new TabardModel { Name = "frameXmlControl1" };

			frameXmlControl = new TabardModelControl(serializationObject);
			Assert.AreEqual(typeof(TabardModel), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(TabardModel), frameXmlControl.TabardModel);
			Assert.IsNotNull(frameXmlControl.TabardModel);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_WorldFrameControl()
		{
			var frameXmlControl = new WorldFrameControl();
			Assert.AreEqual(typeof(WorldFrame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(WorldFrame), frameXmlControl.WorldFrame);
			Assert.IsNotNull(frameXmlControl.WorldFrame);
			var serializationObject = new WorldFrame { Name = "frameXmlControl1" };

			frameXmlControl = new WorldFrameControl(serializationObject);
			Assert.AreEqual(typeof(WorldFrame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(WorldFrame), frameXmlControl.WorldFrame);
			Assert.IsNotNull(frameXmlControl.WorldFrame);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}


		[Test(Description = "")]
		public void Test_TextureControl()
		{
			var frameXmlControl = new TextureControl();
			Assert.AreEqual(typeof(Texture), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Texture), frameXmlControl.Texture);
			Assert.IsNotNull(frameXmlControl.Texture);
			var serializationObject = new Texture { Name = "frameXmlControl1" };

			frameXmlControl = new TextureControl(serializationObject);
			Assert.AreEqual(typeof(Texture), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Texture), frameXmlControl.Texture);
			Assert.IsNotNull(frameXmlControl.Texture);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);

			frameXmlControl.Texture.File = "TestFile.blp";
			frameXmlControl.MinimumSize = new Size(frameXmlControl.MinimumSize.Width, frameXmlControl.MinimumSize.Height);
			frameXmlControl.Size = new Size(32,32);
			frameXmlControl.DrawControl(graphics, frameXmlControl.Bounds);
		}

		[Test(Description = "")]
		public void Test_TaxiRouteFrameControl()
		{
			var frameXmlControl = new TaxiRouteFrameControl();
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(Slider), frameXmlControl.Slider);
			//Assert.IsNotNull(frameXmlControl.Slider);
			var serializationObject = new TaxiRouteFrame { Name = "frameXmlControl1" };

			frameXmlControl = new TaxiRouteFrameControl(serializationObject);
			Assert.AreEqual(typeof(Frame), frameXmlControl.SerializationObjectType);
			//Assert.IsInstanceOfType(typeof(ScrollingMessageFrame), frameXmlControl.Slider);
			//Assert.IsNotNull(frameXmlControl.Slider);
			//Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);
		}

		[Test(Description = "")]
		public void Test_UiControl()
		{
			var frameXmlControl = new UiControl();
			Assert.AreEqual(typeof(Ui), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Ui), frameXmlControl.Ui);
			Assert.IsNotNull(frameXmlControl.Ui);
			var serializationObject = new Ui();

			frameXmlControl = new UiControl(serializationObject);
			Assert.AreEqual(typeof(Ui), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(Ui), frameXmlControl.Ui);
			Assert.IsNotNull(frameXmlControl.Ui);
			Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);

			Assert.AreEqual("Ui", frameXmlControl.Name);
			frameXmlControl.Invalidate();
		}


		[Test(Description = "")]
		public void Test_LayoutFrameControl()
		{
			var frameXmlControl = new LayoutFrameControl();
			Assert.AreEqual(typeof(LayoutFrame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(LayoutFrame), frameXmlControl.LayoutFrame);
			Assert.IsNotNull(frameXmlControl.LayoutFrame);
			var serializationObject = new LayoutFrame { Name = "layoutFrameControl1" };

			//var parentControl = new FrameControl();
			frameXmlControl = new LayoutFrameControl(serializationObject);// {Parent = parentControl};

			Assert.AreEqual(typeof(LayoutFrame), frameXmlControl.SerializationObjectType);
			Assert.IsInstanceOfType(typeof(LayoutFrame), frameXmlControl.LayoutFrame);
			Assert.IsNotNull(frameXmlControl.LayoutFrame);
			//Assert.AreSame(serializationObject, frameXmlControl.SerializationObject);

			Assert.IsFalse(frameXmlControl.IsHidden);
		}

		#endregion


	}
}